<?php

/**
 * 语言模型分组界面（废弃可以删了）
 */

namespace app\api\controller;

use think\Controller;
use app\common\Script;
use app\script\controller\Script as AppScript;

class Languagemodel extends Controller
{
    protected $lm_model;

    public function __construct()
    {
        parent::__construct();
        $this->lm_model = Model('LanguageModel');
    }
    /**
     * 
     */
    public function list()
    {
        $lm_model = $this->lm_model;
        $list = $lm_model->getList();
        if ($list === false) {
            return resultArray(['error' => $lm_model->getError()]);
        }
        return resultArray(['data' => ['list' => $list]]);
    }

    /**
     * 
     */
    public function exchange()
    {
        // if ($GLOBALS['userInfo']['id'] != 1) {
        //     return resultArray(['error' => '非管理员不能修改模型']);
        // }
        $id = input('param.id');
        $lm_model = $this->lm_model;
        $_res = $lm_model->exchangeModel($id);
        if (!$_res) {
            return resultArray(['error' => $lm_model->getError()]);
        }
        //发送通知
        $post_data_json = json_encode(['type' => 'lmChange', 'name' => $_res->md_name]);
        $url = config('huisheng.workerman_forwarding_url');
        $res = curl_post($url, ['data' => $post_data_json]);

        //调用脚本
        $script = new Script();
        $script->asrExchangeModel($_res->type);

        return resultArray(['data' => '']);
    }
}
